home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / client.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1997-08-26  |  1.4 KB  |  63 lines

  1. #!/bin/sh
  2. # @(#) client.sh 1.0 93/12/04
  3. # 93/12/04 John H. DuBois III
  4. # Minimal shell script substitute for the real client program.
  5. # Yes, the way of dealing with cat is lame.
  6.  
  7. Port=3502
  8. Usage="Usage: client [-u username] host [service [arg ...]]"
  9. if [ "$1" = -u ]
  10. then
  11.     username=$2
  12.     shift
  13.     shift
  14. fi
  15.  
  16. if [ $# -lt 1 ]
  17. then
  18.     echo "No hostname specified."
  19.     echo "$Usage"
  20.     exit 1
  21. fi
  22.     
  23. host=$1
  24. shift
  25.  
  26. if [ $# -lt 1 ]
  27. then
  28.     service=LIST
  29. else
  30.     service=$1
  31.     shift
  32. fi
  33.  
  34. args="$service
  35. $username"
  36. # empty arg terminates argument list and avoids error if no args
  37. for arg in "$@" ""
  38. do
  39.     args="$args
  40. $arg"
  41. done
  42.  
  43. tmpfile=client.$$
  44.  
  45. # Save stderr on fd 3 so that telnet can use it,
  46. # and then dump it for everything else.
  47. exec 3>&2
  48. exec 2>/dev/null
  49.  
  50. # Echo service request parameters into telnet, and then cat tty input to it.
  51. # Save pid in a tmpfile so that parent can kill cat if neccessary.
  52. # Save pid first to ensure it is done before telnet terminates
  53.  
  54. # kill cat if it's still hanging around
  55. # bsd 4.2 sh insists that read be done in a subshell to which the redirection
  56. # is done; also, it hangs waiting for the cat, so the cat-killing must be
  57. # done in a subshell with the telnet... thus, two levels of subshells.  eww.
  58.  
  59. sh -c "echo \$$ > $tmpfile; echo '$args'; exec cat" | \
  60. (telnet "$host" $Port 2>&3; (read pid ; kill -9 $pid) < $tmpfile)
  61.  
  62. rm -f $tmpfile
  63.